<template>
  <div class="Chief-Three" chief-style-set>
    <Title title="融资情况" more :MoreUrl='MoreJump(this, "FinancingSituation", 1)'></Title>
    <div class="content-h-auto" chief-style-set>
      <Charts :pChartsOption="ChartsOption"></Charts>
    </div>
  </div>
</template>

<script>
import Title from "@/components/baseTitle";
import Charts from "@/components/portalEcharts/BarEcharts";
import { rptVisPrjRzstatus } from "@/api/portalChief";
import { MoreJump } from "@/util/util";
export default {
  name: "Chief-Three",
  components: {
    Title, Charts
  },
  data () {
    return {
      ChartsOption: {},
      MoreJump
    };
  },
  created () {
    rptVisPrjRzstatus(this.$store.state.user.project.projectNo).then(res => {
      this.disposeData(res);
    });
  },
  methods: {
    // eslint-disable-next-line valid-jsdoc
    /**
    * 处理数据，生成渲染echart的数据格式
    * @param {Object} res 接口返回数据
    */
    disposeData (res) {
      if (res.status === 200 && res.data.code === 0 && res.data.data.length > 0) {
        this.ChartsOption = {
          xAxisNameList: ["本月", "本年"],
          BarList: [
          ],
          needLine: true,
          LineList: [
          ]
        };
        let colorList = ["#5A9BD5", "#4473C5", "#A5A5A5", "#FFC001"];
        let list = res.data.data;
        let nameList = [];
        Object.keys(list[0].data).forEach(item => {
          nameList.push({
            name: item,
            data: []
          });
        });
        list.forEach((item, index) => {
          nameList.forEach((nitem, n) => {
            nameList[n].data.push(item.data[nitem.name]);
          });
        });
        nameList.forEach((item, index) => {
          if (item.name.indexOf("利率") === -1) {
            this.ChartsOption.BarList.push({
              name: item.name,
              data: item.data,
              barWidth: 20,
              color: colorList[index]
            });
          } else {
            item.data.forEach((Item, i) => {
              if (Item.indexOf("%") !== -1) {
                Number(item.data[i] = Item.split("%")[0]);
              }
            });
            this.ChartsOption.LineList.push({
              name: item.name,
              data: item.data,
              color: colorList[index]
            });
          }
        });
      } else {
        this.ChartsOption = {};
      }
    }
  }
};
</script>
